package com.accgm.api.resources.user;

import net.sf.json.JSONObject;

import org.restlet.Request;

import com.accgm.api.db.dao.AccgmUserDao;
import com.accgm.api.db.model.AccgmUserModel;
import com.accgm.api.resources.base.BaseResource;

public class UpdateUserResource extends BaseResource {

	AccgmUserDao accgmUserDao = AccgmUserDao.getInstance(); 
	@Override
	protected void initParams(Request request) {
		
	}

	@Override
	protected JSONObject getMethod(JSONObject json) {
		AccgmUserModel accgmUser = accgmUserDao.findByPrimaryKey(userId);
		String username = getParameter("username","");//姓名
		String sex = getParameter("sex","");//性别
		String birthday = getParameter("birthday","");//出生日期
		String height = getParameter("height","");//身高
		String weight = getParameter("weight","");//体重
		Integer medical = getParameter("medical",-1);//糖尿病类型
		String ear_lobe = getParameter("ear_lobe","");//耳垂厚度
		String ear_hole = getParameter("ear_hole","");//是否穿耳环
		AccgmUserModel updateAccgmUser = new AccgmUserModel();
		updateAccgmUser.setId(accgmUser.getId());
		if(!username.equals("")){
			updateAccgmUser.setName(username);
		}
		if(!sex.equals("")){
			updateAccgmUser.setSex(sex);
		}
		if(!birthday.equals("")){
			updateAccgmUser.setBirthday(birthday);
		}
		if(!height.equals("")){
			updateAccgmUser.setHeight(height);
		}
		if(!weight.equals("")){
			updateAccgmUser.setWeight(weight);
		}
		if(medical != -1){
			updateAccgmUser.setCheckMessage(medical);
		}
		if(!ear_lobe.equals("")){
			updateAccgmUser.setEarlobeWidth(ear_lobe);
		}
		if(!ear_hole.equals("")){
			updateAccgmUser.setIsEarPiercing(ear_hole);
		}
		accgmUserDao.updateAny(updateAccgmUser);
		return succRequest("更新成功",json);
	}

	@Override
	protected JSONObject postMethod(JSONObject json) {
		return this.getMethod(json);
	}

}
